package me.zhanshi123.timedworld;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeLimit {
    private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");

    public TimeLimit(String limitStr) {
        String[] args = limitStr.split("-");
        String startStr = args[0];
        String endStr = args[1];
        try {
            start = simpleDateFormat.parse(startStr);
            end = simpleDateFormat.parse(endStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    private Date start;
    private Date end;

    private SimpleDateFormat current = new SimpleDateFormat("yyyy-MM-dd");

    public boolean isAvailable() {
        String text = current.format(new Date());
        Date date;
        try {
            date = current.parse(text);
        } catch (ParseException e) {
            return false;
        }
        long time = System.currentTimeMillis() - 28800000 - date.getTime();
        /*
        System.out.println("start: " + start.getTime());
        System.out.println("now: " + time);
        System.out.println("end: " + end.getTime());
         */
        return start.getTime() < time && end.getTime() >= time;
    }
}
